// 参考题解：https://www.acwing.com/solution/content/60478/

#include <bits/stdc++.h>
using namespace std;
const int N = 110, M = N << 1;
int n, w[M], f[M][M];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> w[i];
    w[n + i] = w[i];
  }
  memset(f, -0x3f, sizeof f);
  for (int len = 2; len <= n + 1; ++len) {  // 从第二个位置开始枚举
    for (int l = 1, r; (r = l + len - 1) <= n << 1; ++l) {
      if (len == 2)
        f[l][r] = 0;
      else {
        for (int k = l + 1; k < r; ++k) {
          f[l][r] = max(f[l][r], f[l][k] + f[k][r] + w[l] * w[k] * w[r]);
        }
      }
    }
  }
  int res = 0;
  for (int l = 1; l <= n; ++l) res = max(res, f[l][l + n]);
  cout << res << endl;
}
